<?php

// @formatter:off
/**
 * @file includes.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-06-03 03:40:32 +0000 (Tue, 03 Jun 2014) $
 *
 * $Id: includes.php 112 2014-06-03 03:40:32Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/config/includes.php $
 */
// @formatter:on

require_once "{$wcPaths["includes-directory"]}/tools.php";
//
// Interdaces.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCPreviews":
		case "WCCountItems":
		case "WCCountComics":
		case "WCCountImages":
		case "WCCountDirectories":
		case "WCCountCollections":
		case "WCCountActions":
		case "WCHardRemove":
		case "WCTrashed":
		case "WCFlowItem":
		case "WCFlowContainer":
			require_once "{$wcPaths["includes-directory"]}/interfaces/{$class}.php";
			break;
	}
});
//
// Basic abstract classes.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCSingleton":
			require_once "{$wcPaths["includes-directory"]}/WCSingleton.abs.php";
			break;
		case "WCFactory":
			require_once "{$wcPaths["includes-directory"]}/WCFactory.abs.php";
			break;
	}
});
//
// Basic classes.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCErrors":
		case "WCParameters":
		case "WCReadRate":
		case "WCTimer":
			require_once "{$wcPaths["includes-directory"]}/{$class}.php";
			break;
		case "WCOption":
		case "WCOptions":
			require_once "{$wcPaths["includes-directory"]}/WCOptions.php";
			break;
		case "WCLogLevel":
		case "WCLog":
			require_once "{$wcPaths["includes-directory"]}/WCLog.php";
			break;
		case "WCPreviewsManager":
			require_once "{$wcPaths["includes-directory"]}/WCPreviews.php";
			break;
	}
});
//
// Database classes.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCConnection":
		case "WCMassiveInstaller":
		case "WCDBIndex":
		case "WCDBIndexJSON":
		case "WCDBTable":
		case "WCDBTableJSON":
			require_once "{$wcPaths["includes-directory"]}/db/{$class}.php";
			break;
		case "WCDBItem":
		case "WCDBItemJSON":
			require_once "{$wcPaths["includes-directory"]}/db/{$class}.abs.php";
			break;
		case "WCDBCheck":
		case "WCDBChecks":
			require_once "{$wcPaths["includes-directory"]}/db/WCDBChecks.php";
			break;
	}
});
//
// Containers.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCContainer":
			require_once "{$wcPaths["includes-directory"]}/containers/WCContainer.php";
			break;
	}
});
//
// Holders.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCHoldersBus":
		case "WCHolderGroupDependant":
		case "WCHolderKeywordDependant":
			require_once "{$wcPaths["includes-directory"]}/holders/WCHoldersBus.php";
			break;
		case "WCHolder":
		case "WCHolderGroup":
		case "WCHolderKeyword":
			require_once "{$wcPaths["includes-directory"]}/holders/{$class}.abs.php";
			break;
		case "WCCommentsHolder":
		case "WCComicsHolder":
		case "WCComicImagesHolder":
		case "WCImagesHolder":
		case "WCDirectoriesHolder":
		case "WCUsersHolder":
		case "WCUserDataHolder":
		case "WCGroupsHolder":
		case "WCTagsHolder":
		case "WCCollectionsHolder":
		case "WCRulesHolder":
		case "WCSearchWordsHolder":
		case "WCLangTranslationHolder":
		case "WCActiveTagsHolder":
			require_once "{$wcPaths["includes-directory"]}/holders/{$class}.php";
			break;
	}
});
//
// Representations.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCRepresentation":
			require_once "{$wcPaths["includes-directory"]}/representations/WCRepresentation.abs.php";
			break;
		case "WCRepresentationGroup":
			require_once "{$wcPaths["includes-directory"]}/representations/WCRepresentationGroup.abs.php";
			break;
		case "WCRepresentationKeyword":
			require_once "{$wcPaths["includes-directory"]}/representations/WCRepresentationKeyword.abs.php";
			break;
		case "WCComment":
		case "WCComic":
		case "WCComicImage":
		case "WCImage":
		case "WCDirectory":
		case "WCUser":
		case "WCUserData":
		case "WCGroup":
		case "WCTag":
		case "WCCollection":
		case "WCRule":
		case "WCSearchWord":
		case "WCLangTranslation":
		case "WCActiveTag":
			require_once "{$wcPaths["includes-directory"]}/representations/{$class}.php";
			break;
	}
});
//
// Rules.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCRuleAction":
		case "WCDirectoryOrganizer":
		case "WCTagsRelator":
			require_once "{$wcPaths["includes-directory"]}/rules/{$class}.php";
			break;
		case "WCActiveTagDirectoryMover":
			require_once "{$wcPaths["includes-directory"]}/rules/WCDirectoryMover.php";
			break;
	}
});
//
// ActiveTags.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCActiveTagHook":
			require_once "{$wcPaths["includes-directory"]}/activetags/WCActiveTagHook.abs.php";
			break;
		case "WCActiveTagGarbage":
		case "WCActiveTagUntagged":
		case "WCActiveTagFewTags":
		case "WCActiveTagBlastTags":
			require_once "{$wcPaths["includes-directory"]}/activetags/{$class}.php";
			break;
	}
});
//
// Parser @{
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCParser":
		case "WCParserNode":
		case "WCParserBehavior":
			require_once "{$wcPaths["includes-directory"]}/parser/{$class}.php";
			break;
	}
	if(preg_match("/WCParserBehavior([A-Z]+)/", $class, $matches)) {
		$knownBehaviors = array(
			"IF",
			"IGNORE",
			"INCLUDE",
			"ISSET",
			"OVER",
			"VAR"
		);

		if(in_array($matches[1], $knownBehaviors)) {
			require_once "{$wcPaths["includes-directory"]}/parser/{$class}.php";
		}
	}
});
/**
 * @var string[string] This is the matrix where every known behavior must be
 * specified.
 * Keys are keywords found as function in parsed text, and values are class'
 * names to be used as parsing handler.
 */
$wcParserBehaviorMatrix = array();
//
// Adding functions to evaluate: @{
$wcParserBehaviorMatrix["IGNORE"] = "WCParserBehaviorIGNORE";
$wcParserBehaviorMatrix["!"] = "WCParserBehaviorIGNORE";
$wcParserBehaviorMatrix["VAR"] = "WCParserBehaviorVAR";
$wcParserBehaviorMatrix["IF"] = "WCParserBehaviorIF";
$wcParserBehaviorMatrix["ISSET"] = "WCParserBehaviorISSET";
$wcParserBehaviorMatrix["INCLUDE"] = "WCParserBehaviorINCLUDE";
$wcParserBehaviorMatrix["OVER"] = "WCParserBehaviorOVER";
//	@}
// @}
//
// Lang.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCTranslate":
		case "WCParserBehaviorTRHEADER":
			require_once "{$wcPaths["includes-directory"]}/lang/{$class}.php";
			break;
		case "WCParserBehaviorTR":
		case "WCParserBehaviorTRV":
			require_once "{$wcPaths["includes-directory"]}/lang/WCParserBehaviorTR.php";
			break;
	}
});
//
// Services.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
//		case "WCServicesFactory": /** @obsolete */
		case "WCCaptchaService":
		case "WCServicesManager":
			require_once "{$wcPaths["includes-directory"]}/services/{$class}.php";
			break;
		case "WCService":
		case "WCServiceDummy":
			require_once "{$wcPaths["includes-directory"]}/services/WCService.abs.php";
			break;
	}
});
//
// Security.
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCSessions":
		case "WCProfile":
		case "WCSession":
		case "WCSessionKeep":
			require_once "{$wcPaths["includes-directory"]}/security/{$class}.php";
			break;
	}
});
//
// Search @{
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCSearch":
		case "WCSearchIndexableHolder":
		case "WCSearchIndexable":
		case "WCSearchScore":
		case "WCSearchResult":
			require_once "{$wcPaths["includes-directory"]}/search/WCSearch.php";
			break;
		case "WCQuery":
		case "WCSearchFactory":
			require_once "{$wcPaths["includes-directory"]}/search/{$class}.php";
			break;
	}
});
$wcSearchHolders[] = "WCComicsHolder";
$wcSearchHolders[] = "WCImagesHolder";
$wcSearchHolders[] = "WCDirectoriesHolder";
$wcSearchHolders[] = "WCTagsHolder";
$wcSearchHolders[] = "WCCollectionsHolder";
$wcSearchHolders[] = "WCRulesHolder";
$wcParserBehaviorMatrix["TR"] = "WCParserBehaviorTR";
$wcParserBehaviorMatrix["TRV"] = "WCParserBehaviorTRV";
$wcParserBehaviorMatrix["TRHEADER"] = "WCParserBehaviorTRHEADER";
// @}
//
// FrontView and MVC @{
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCViewManager":
		case "WCViewController":
		case "WCActionController":
		case "WCLayoutController":
		case "WCViewInfoFactory":
		case "WCParserBehaviorDELAYEDLOAD":
		case "WCParserBehaviorACTIONCALL":
			require_once "{$wcPaths["mvc"]["include"]}/{$class}.php";
			break;
		case "WCFVMenuNode":
		case "WCFVMenu":
			require_once "{$wcPaths["mvc"]["tools"]}/WCFVMenu.php";
			break;
		case "WCFVTopBarNode":
		case "WCFVTopBar":
			require_once "{$wcPaths["mvc"]["tools"]}/WCFVTopBar.php";
			break;
		case "WCFVBoxes":
			require_once "{$wcPaths["mvc"]["tools"]}/WCFVBoxes.php";
			break;
		case "WCFVPager":
			require_once "{$wcPaths["mvc"]["tools"]}/WCFVPager.php";
			break;
	}
});
$wcParserBehaviorMatrix["DELAYEDLOAD"] = "WCParserBehaviorDELAYEDLOAD";
$wcParserBehaviorMatrix["ACTIONCALL"] = "WCParserBehaviorACTIONCALL";
// @}
//
// Shell tools
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCCron":
			require_once "{$wcPaths["includes-directory"]}/WCCron.php";
			break;
		case "WCCronTool":
			require_once "{$wcPaths["includes-directory"]}/WCCronTool.php";
			break;
		case "WCToolsManager":
			require_once "{$wcPaths["includes-directory"]}/WCToolsManager.php";
			break;
		case "WCTool":
			require_once "{$wcPaths["includes-directory"]}/WCTool.php";
			break;
	}
});
//
// Flows
spl_autoload_register(function($class) {
	global $wcPaths;

	switch($class) {
		case "WCFlow":
		case "WCFlowManager":
			require_once "{$wcPaths["includes-directory"]}/flow/{$class}.php";
			break;
	}
});
